﻿/****** Object:  Table [dbo].[Appointments] ******/

CREATE TABLE [Appointments](

      [ID] [int] IDENTITY(1,1) NOT NULL,

      [Summary] [nvarchar](255)   NOT NULL,

      [Start] [datetime] NOT NULL,

      [End] [datetime] NOT NULL,

      [RecurrenceRule] [nvarchar](1024)   NULL,

      [MasterEventId] [int] NULL,

      [Location] [nvarchar](255)   NULL,

      [Description] [ntext]  NULL,

      [BackgroundId] [int] NOT NULL CONSTRAINT [DF_Appointments_BackgroundId]  DEFAULT ((1)),

 		PRIMARY KEY(ID)

)

GO

/****** Object:  Table [dbo].[Resources] ******/
CREATE TABLE [Resources](

      [ID] [int] IDENTITY(1,1) NOT NULL,

      [Name] [nvarchar](255) NOT NULL,

      [Image] [binary](4000) NULL,

		PRIMARY KEY([ID])

)

GO

/****** Object:  Table [dbo].[AppointmentsResources] ******/
CREATE TABLE [AppointmentsResources](

      [AppointmentID] [int] NOT NULL,

      [ResourceID] [int] NOT NULL,

  PRIMARY KEY ([AppointmentID],[ResourceID])

)

GO

ALTER TABLE [AppointmentsResources]  ADD  CONSTRAINT [AppointmentsResources_Appointments] FOREIGN KEY([AppointmentID])

REFERENCES [Appointments] ([ID])

ON DELETE CASCADE

GO

ALTER TABLE [AppointmentsResources] CHECK CONSTRAINT [AppointmentsResources_Appointments]

GO

ALTER TABLE [AppointmentsResources]  ADD  CONSTRAINT [AppointmentsResources_Resources] FOREIGN KEY([ResourceID])

REFERENCES [Resources] ([ID])

GO

ALTER TABLE [AppointmentsResources] CHECK CONSTRAINT [AppointmentsResources_Resources]